package com.system.member.controller;


import com.system.common.resp.CommonResp;
import com.system.common.resp.MemberLoginResp;
import com.system.member.domain.R;
import com.system.member.req.MemberLoginReq;
import com.system.member.req.MemberRegisterReq;
import com.system.member.req.MemberSendCodeReq;
import com.system.member.service.MemberService;
import com.system.member.utils.sendMessage.AliyunUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


@RestController
@RefreshScope
public class MemberController {

    @Autowired
    private MemberService memberService;
    @Autowired
    Environment environment;
    @Autowired
    AliyunUtil aliyunUtil;



    @Value("${test.nacos}")
    private String  testNacos;

    @RequestMapping("/test")
    public String test(){
        return String.format("%s！ 端口：%s", testNacos,environment.getProperty("local.server.port"));
    }

    @PostMapping("/register")
    public CommonResp<Long> register(@Valid @RequestBody MemberRegisterReq req) {
        long register = memberService.register(req);
        return new CommonResp<>(register);
    }

    @PostMapping("/send-code")
    public CommonResp<Long> sendCode(@Valid @RequestBody MemberSendCodeReq req) {
        memberService.sendCode(req);
        return new CommonResp<>();
    }

    @PostMapping("/login")
    public CommonResp<MemberLoginResp> login(@Valid @RequestBody MemberLoginReq req) {
        MemberLoginResp resp = memberService.login(req);
        return new CommonResp<>(resp);
    }

}
